package com.gjy.aviator.function;

import com.googlecode.aviator.runtime.function.AbstractFunction;
import com.googlecode.aviator.runtime.type.AviatorObject;
import com.googlecode.aviator.runtime.type.AviatorStringBuilder;

import java.util.Map;

/**
 * @author gjy
 * @version 1.0
 * @since 2024-11-04 18:46:50
 */
public class NumberFormatFunction extends AbstractFunction {

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) {
        Number number = arg1.numberValue(env);
        String format = arg2.stringValue(env);
        return new AviatorStringBuilder(String.format(format, number));
    }

    @Override
    public String getName() {
        return "numberFormat";
    }
}
